
import time
import keyboard
import pydirectinput

from src import enum


pydirectinput.KEYBOARD_MAPPING['up'] = 0xC8
pydirectinput.KEYBOARD_MAPPING['down'] = 0xD0
pydirectinput.KEYBOARD_MAPPING['left'] = 0xCB
pydirectinput.KEYBOARD_MAPPING['right'] = 0xCD

def on_key_press(event):
    print('keyPress', event)


def on_key_release(event):
    print('keyRelease', event)


# keyboard.on_press(on_key_press)
# keyboard.on_release(on_key_release)


def press(key, times):
    print('autoPress', key)
    times = times/1000
    if enum.setting['keyboardModel'] == "keyboard":
        keyboard.press(key)
        time.sleep(times)
        keyboard.release(key)

    elif enum.setting['keyboardModel'] == "directinput":
        pydirectinput.press(key, interval=times, _pause=False)





